package com.simba.server.commands.impl.update;

import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;

public class RenewBarcodeInfoExpiredCmd implements ICommand {
    public static final String NAME = "RenewBarcodeInfoExpiredCmd";
    private final String barcode;
    private final String sql = "update tt_packet_off_info set expiredFlag=1 where barcode=?;";
    //private final String historySql = "update tt_packet_off_info_history set expiredFlag=1 where barcode=?;";
    private final String reportSql = "update tt_packet_off_info_report set expiredFlag=1 where barcode=?;";


    public RenewBarcodeInfoExpiredCmd(String barcode)
    {
        this.barcode = barcode;
    }
    @Override
    public String getName() {
        return RenewBarcodeInfoExpiredCmd.NAME;
    }

    @Override
    public Boolean run(Object params) {
        Boolean ret = false;

        if (!(params instanceof DbOperator))
        {
            return ret;
        }

        try
        {
            DbOperator dbOperator = (DbOperator) params;

            dbOperator.prepareStatement(this.sql);
            dbOperator.setString(1, barcode);
            int rs = dbOperator.executeUpdate();

//            dbOperator.prepareStatement(this.historySql);
//            dbOperator.setString(1, barcode);
//            int historyRs = dbOperator.executeUpdate();

            dbOperator.prepareStatement(this.reportSql);
            dbOperator.setString(1, barcode);
            dbOperator.executeUpdate();

            if (rs > 0)
            {
                ret = true;
            }
            else
            {
                ret = false;
            }
        }
        catch (Exception ex)
        {
            ret = false;
        }

        return ret;
    }
}
